package cn.yunhe.servlet;

import cn.yunhe.entity.OrderDetail;
import cn.yunhe.entity.User;
import cn.yunhe.service.OrderDetailService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;
@WebServlet("/GetUserShoppingServlet")
public class GetUserShoppingServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session=req.getSession();
        User user= (User) session.getAttribute("Curr_User");
        if(user==null){
            resp.sendRedirect("login.jsp");
        }else {
            OrderDetailService orderDetailService = new OrderDetailService();
            List<OrderDetail> orderDetailList = orderDetailService.getUserShopping(user.getUserid());
            req.setAttribute("orderDetailList", orderDetailList);
            req.getRequestDispatcher("shopping.jsp").forward(req, resp);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
